﻿//-----------------------------------------------------------------------------
// <copyright file="CommonFrameworkElementServices.cs" company="William E. Kempf">
//     Copyright (c) William E. Kempf.
// </copyright>
//-----------------------------------------------------------------------------

namespace Onyx.Windows
{
    using System;
    using System.Windows;

    /// <summary>
    /// Implements common services for <see cref="FrameworkElement"/> and
    /// <see cref="FrameworkContentElement"/> types.
    /// </summary>
    internal class CommonFrameworkElementServices : ServicesBase, IElementLifetime
    {
        /// <summary>
        /// The <em>view element</em>.
        /// </summary>
        private readonly IFrameworkObject element;

        /// <summary>
        /// Initializes a new instance of the <see cref="CommonFrameworkElementServices"/> class.
        /// </summary>
        /// <param name="element">The <em>view element</em>.</param>
        internal CommonFrameworkElementServices(IFrameworkObject element)
        {
            this.element = element;
        }

#if WPF
        /// <summary>
        /// Occurs when the <em>view element</em> is initialized.
        /// </summary>
        event EventHandler IElementLifetime.Initialized
        {
            add
            {
                this.element.Initialized += value;
            }

            remove
            {
                this.element.Initialized -= value;
            }
        }
#endif

        /// <summary>
        /// Occurs when the <em>view element</em> is loaded.
        /// </summary>
        event RoutedEventHandler IElementLifetime.Loaded
        {
            add
            {
                this.element.Loaded += value;
            }

            remove
            {
                this.element.Loaded -= value;
            }
        }

#if WPF
        /// <summary>
        /// Occurs when the <em>view element</em> is unloaded.
        /// </summary>
        event RoutedEventHandler IElementLifetime.Unloaded
        {
            add
            {
                this.element.Unloaded += value;
            }

            remove
            {
                this.element.Unloaded -= value;
            }
        }
#endif
    }
}
